package com.example.onlinemonitoring.serviceImpl;

import com.example.onlinemonitoring.model.Dlhlsepsensor;
//import com.example.onlinemonitoring.model.Dlhlsensor;
import com.example.onlinemonitoring.model.Dlhlsephistory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.example.onlinemonitoring.Util.tem.SensorAbstractBaseService;
import com.example.onlinemonitoring.dao.DlhlsephistoryMapper;
import com.example.onlinemonitoring.dao.DlhlsepsensorMapper;
import com.example.onlinemonitoring.service.DlhlsepsensorService;

import tk.mybatis.mapper.entity.Example;

import com.example.onlinemonitoring.model.common.MyResult;
import com.example.onlinemonitoring.model.common.chartres;
import com.example.onlinemonitoring.model.common.dcurrentaddrconfig;
import com.example.onlinemonitoring.Util.HexUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import com.example.onlinemonitoring.model.common.MyResult;
import org.springframework.beans.factory.annotation.Autowired;
import com.example.onlinemonitoring.model.common.dcurrentaddrconfig;
import org.springframework.transaction.annotation.Transactional;

import tk.mybatis.mapper.entity.Example;

/**
 * @description Dlhlsepsensor接口实现
 * @author generator
 * @since 2023-08-07 13:28:03
 */
@Service("dlhlsepServiceImpl")
public class DlhlsepsensorServiceImpl extends SensorAbstractBaseService<Dlhlsepsensor, Dlhlsephistory>
        implements DlhlsepsensorService {
    // 这里需要重写getDt方法,用来处理图表数据
    // public String[] getDt(List<Dlhlsephistory> list,String[] dt,chartres
    // cts,float[][] sres,SimpleDateFormat sdf,SimpleDateFormat
    // csdf,SimpleDateFormat sdf2){return null;}
    @Autowired
    private DlhlsepsensorMapper dlhlsepsensormapper;
    @Autowired
    private DlhlsephistoryMapper dlhlsephistorymapper;

    public MyResult<dcurrentaddrconfig> selectaddr(Dlhlsepsensor record) {
        MyResult<dcurrentaddrconfig> result = new MyResult<dcurrentaddrconfig>();
        List<dcurrentaddrconfig> list = dlhlsepsensormapper.selectaddr(record);
        if (list.size() != 0) {
            result.setCode(0);
            result.setMsg("success");
            result.setCount(list != null && !list.isEmpty() ? list.size() : 0);
            result.setData(list);
        } else {
            result.setCode(1);
            result.setMsg("数据为空");
        }
        return result;
    }

    @Transactional
    public MyResult<Integer> Updatelastdcurrentaddr(dcurrentaddrconfig ptconfig, Integer stationid,
            Integer devicegroup) {
        Example example = new Example(Dlhlsepsensor.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("stationid", stationid);
        criteria.andEqualTo("devicegroup", devicegroup);
        dlhlsepsensormapper.setlastdcurrentaddr(stationid, devicegroup, ptconfig.getlastdcurrentaddr());
        if (ptconfig.getDlhlmin() != 0 && ptconfig.getDlhlmax() != 0) {
            Dlhlsepsensor record = new Dlhlsepsensor();
            record.setLastdcurrentaddr(ptconfig.getlastdcurrentaddr());
            criteria.andGreaterThanOrEqualTo("deviceaddr", ptconfig.getDlhlmin());
            criteria.andLessThanOrEqualTo("deviceaddr", ptconfig.getDlhlmax());
            updateByExampleSelective(record, example);
        }
        return new MyResult<Integer>(true);
    }

    public List<Dlhlsepsensor> getlastdcurrentaddrModel(Dlhlsepsensor alarm) {
        Example example = new Example(Dlhlsepsensor.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("stationid", alarm.getStationid());
        criteria.andEqualTo("devicegroup", alarm.getDevicegroup());
        criteria.andEqualTo("lastdcurrentaddr", alarm.getLastdcurrentaddr());
        return dlhlsepsensormapper.selectByExample(example);
    }
}
